home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 2).iso / 1133 / params.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-17  |  3.0 KB  |  141 lines

  1. /*
  2. **
  3. **  File:           PARAMS.C
  4. **  Description:    Loaded and holds the parameters of a neural network
  5. **  Platform:       Windows
  6. **
  7. **
  8. */
  9. #include <windows.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "nndefs.h"
  14. #include "params.h"
  15.  
  16.     void Logit(const char* fmt, ...);
  17.     int fgetstr (FILE *fd, LPSTR str);
  18.     int fgetint(FILE *fd);
  19.     long fgetlong(FILE *fd);
  20.     float fgetfloat(FILE *fd);
  21.  
  22. /*
  23. ** CreateParams
  24. **
  25. ** This function is called to create a new params structure and initialize it to the
  26. ** default settings
  27. ** 
  28. **
  29. ** Arguments:
  30. **
  31. **      None
  32. **
  33. ** Returns:
  34. **
  35. **      PARAMS            returns a pointer to the newly created PARAMS structure
  36. */
  37.  
  38. PARAMS *CreateParams( )
  39. {
  40.     PARAMS *pM;
  41.     pM = (PARAMS *) malloc (sizeof(PARAMS));
  42.  
  43.     pM->m_TrainFlags=0;
  44.     pM->m_AImaxhid=4;
  45.     pM->m_goodness=3;
  46.     pM->m_autosave = 1000;
  47.     pM->m_seed = 15;
  48.     pM->m_eon = 100;
  49.  
  50.     pM->m_cnt_max = 1000;
  51.  
  52.     pM->m_hiddegrad=0.75f;
  53.     pM->m_errtol = 0.001f;
  54.     pM->m_goodrsq = .9f;
  55.     pM->m_signinc = .05f;
  56.     pM->m_nosigninc = .005f;
  57.     pM->m_alpha = .8f;
  58.     pM->m_theta = .5f;
  59.     pM->m_randz = .5f;
  60.     pM->m_inrandzdiv = 0.f;
  61.     pM->m_tol = .05f;
  62.     pM->m_learning_rate = .75f;
  63.     pM->m_Hlearning_rate = 1.5f;
  64.     pM->m_tlearning_rate = .75f;
  65.     pM->m_inoutlearn = .1f;
  66.                           
  67.     return pM;                              
  68. }
  69.  
  70. /*
  71. ** ImportParams
  72. **
  73. ** This function is called to read in a params structure from an ENN file
  74. ** 
  75. **
  76. ** Arguments:
  77. **
  78. **      FILE *fd          A pointer to the open ENN file
  79. **      PARAMS *pM        A pointer to the blank params sructure
  80. **
  81. ** Returns:
  82. **
  83. **      int            returns a zero if okay otherwise a -1
  84. */
  85.  
  86. int ImportParams (FILE *fd, PARAMS *pM)
  87. {
  88.     static char cdummy[80];
  89.     int ex;
  90.  
  91. #ifdef VERBOSE
  92.     Logit("Start import params\n");
  93. #endif
  94.     
  95.     fgetstr(fd,cdummy);
  96.     if (strncmp("P00",cdummy,3)!=0) goto errorexit;
  97.     ex = fgetint(fd);
  98.     if (ex != EXPORTVERSION) {
  99. #ifdef VERBOSE
  100.         Logit("The ENN file is the wrong export version\n");
  101. #endif
  102.         return -1;
  103.     }
  104.  
  105.     fgetstr(fd,cdummy);
  106.     if (strncmp("P01",cdummy,3)!=0) goto errorexit;
  107.     pM->m_TrainFlags = fgetint(fd);
  108.     pM->m_AImaxhid   = fgetint(fd);
  109.     pM->m_goodness   = fgetint(fd);
  110.     pM->m_autosave   = fgetint(fd);
  111.     pM->m_seed       = fgetint(fd);
  112.     pM->m_eon        = fgetint(fd);
  113.  
  114.     fgetstr(fd,cdummy);
  115.     if (strncmp("P02",cdummy,3)!=0) goto errorexit;
  116.     pM->m_cnt_max = fgetlong(fd);
  117.     pM->m_hiddegrad = fgetfloat(fd);
  118.     pM->m_errtol    = fgetfloat(fd);
  119.     pM->m_goodrsq  = fgetfloat(fd);
  120.     pM->m_signinc   = fgetfloat(fd);
  121.     pM->m_nosigninc  = fgetfloat(fd);
  122.     pM->m_alpha      = fgetfloat(fd);
  123.  
  124.     fgetstr(fd,cdummy);
  125.     if (strncmp("P03",cdummy,3)!=0) goto errorexit;
  126.     pM->m_theta     = fgetfloat(fd);
  127.     pM->m_randz     = fgetfloat(fd);
  128.     pM->m_inrandzdiv = fgetfloat(fd);
  129.     pM->m_tol        = fgetfloat(fd);
  130.     pM->m_learning_rate = fgetfloat(fd);
  131.     pM->m_Hlearning_rate = fgetfloat(fd);
  132.     pM->m_tlearning_rate = fgetfloat(fd);
  133.     pM->m_inoutlearn = fgetfloat(fd);
  134.     return 0;                                     
  135.  
  136. errorexit:        
  137.     return -1;
  138.     
  139. }
  140.  
  141.